unit DoaMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ActiveX, ComObj, ShellAPI, Buttons, Registry;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    GroupBox2: TGroupBox;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button14: TButton;
    Button15: TButton;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Label7: TLabel;
    Edit7: TEdit;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

// define new struct to get over 2G memory size.  
Type  
  TMemoryStatusEx = packed record
    dwLength: DWORD;
    dwMemoryLoad: DWORD;
    ullTotalPhys: Int64;
    ullAvailPhys: Int64;
    ullTotalPageFile: Int64;
    ullAvailPageFile: Int64;
    ullTotalVirtual: Int64;
    ullAvailVirtual: Int64;
    ullAvailExtendedVirtual: Int64;
  end;


implementation

{$R *.dfm}

// define new struct to get over 2G memory size.  
Function GlobalMemoryStatusEx(var lpBuffer: TMemoryStatusEx): BOOL; stdcall; external kernel32; 

function GetWMIProperty(WMIType, WMIProperty: string): string;
var Wmi, Objs, Obj: OleVariant;
  C: Cardinal;
  i,Len:integer;
  tempItem:IEnumVariant;
begin
  Wmi:= CreateOleObject('WbemScripting.SWbemLocator');
  Objs := Wmi.ConnectServer('.','root\cimv2').ExecQuery('Select * from Win32_' + WMIType);
  tempItem:=IEnumVariant(IUnknown(Objs._NewEnum));
  Result:='';
  while (tempItem.Next(1, obj, c) = S_OK) do
  begin
    Obj := Obj.Properties_.Item(WMIProperty, 0).Value;
    if not VarIsNull(obj) then
    begin
      try
        Result :=Result +trim(Obj);
      except
        Result := 'Error';
      end;
      break;
    end;
  end;
end;

function DoaFunc(FuncName: string): string;
begin
  ShellExecute(Application.Handle, 'open', PChar(FuncName), '', nil, SW_SHOW);    
end;


procedure TForm1.FormCreate(Sender: TObject);
var
  MemInfo: TMemoryStatusEx;
  reg: TRegistry;
begin
  // define new struct to get over 2G memory size.  
  MemInfo.dwLength:=sizeof(TMemoryStatusEx);
  
  reg := TRegistry.Create;
  reg.RootKey := HKEY_LOCAL_MACHINE;
  if reg.OpenKey('HARDWARE\DESCRIPTION\System\BIOS', false) then
  begin
    Edit5.Text := reg.ReadString('BIOSVersion');
  end;   
  GlobalMemoryStatusEx(MemInfo);
  
  Edit1.Text := GetWMIProperty('Processor', 'Name');
  Edit2.Text := IntToStr(MemInfo.ullTotalPhys div 1024 div 1024) + ' M';
  Edit3.Text := GetWMIProperty('DiskDrive', 'Caption');
  Edit4.Text := GetWMIProperty('CDROMDrive', 'Caption');
  //Edit5.Text := GetWMIProperty('BIOS', 'BIOSVersion');
  Edit6.Text := GetWMIProperty('Processor', 'Name');
  Edit7.Text := GetWMIProperty('DesktopMonitor', 'PNPDeviceID');
  reg.Destroy;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  DoaFunc('batch\USB.bat');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  DoaFunc('batch\speaker.bat');
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
  DoaFunc('batch\mic.bat');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
    DoaFunc('batch\lan.bat');
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
    DoaFunc('batch\cardreader.bat');
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
    DoaFunc('batch\hdmi.bat');
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  DoaFunc('batch\vga.bat');
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  DoaFunc('batch\ac.bat');
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
  DoaFunc('batch\odd.bat');
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
  DoaFunc('batch\lcd.bat');
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
  DoaFunc('batch\ccd.bat');
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
  DoaFunc('batch\keyboard.bat');
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
    DoaFunc('batch\touchpad.bat');
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
  DoaFunc('batch\led.bat');
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
  DoaFunc('batch\lid.bat');
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  DoaFunc('batch\config.bat');
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
  DoaFunc('batch\HddUsage.bat');
end;

end.
